import hashlib
import json

import requests
import re,time
from lxml import etree


url = 'https://www.mashangpa.com/api/problem-detail/4/data/'
headers = {
    # ":authority": "www.mashangpa.com",
    # ":method": "GET",
    # ":path": "/api/problem-detail/4/data/?page=1&sign=532a0d39aa96a196b84bae0327d80271&_ts=1761961487332",
    # ":scheme": "https",
    "accept": "*/*",
    "accept-encoding": "gzip, deflate, br, zstd",
    "accept-language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
    "cache-control": "no-cache",
    "cookie": "Hm_lvt_0d2227abf9548feda3b9cb6fddee26c0=1761961373; HMACCOUNT=E5B64E4D33FFD801; sessionid=hsaf1lsm222vk0pzp1zh8yzugismxwx1; Hm_lpvt_0d2227abf9548feda3b9cb6fddee26c0=1761961487",
    "pragma": "no-cache",
    "priority": "u=1, i",
    "referer": "https://www.mashangpa.com/problem-detail/4/",
    "sec-ch-ua": "\"Google Chrome\";v=\"141\", \"Not?A_Brand\";v=\"8\", \"Chromium\";v=\"141\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\"",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-origin",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36"
}


total = 0

for i in range(1, 21):
    ts_ms = int(time.time() * 1000)
    print(f'正在爬取第{i}页')
# 3. 按规则拼字符串
    raw_str = f'tuling{ts_ms}{i}'

# # 4. 计算 MD5
    sign = hashlib.md5(raw_str.encode('utf-8')).hexdigest()
#
    params = {
        "page": i,
        "sign": sign,
        "_ts": ts_ms

    }
    res = requests.get(url,params= params,headers=headers)

    # print(res.content.decode('utf8'))
    # print(res.json())
    current_array = res.json().get('current_array')
    print(current_array)
    for num in current_array:
       total += num
print(total)



